import { ref } from 'vue'
import { defineStore } from 'pinia'
import type { PackageData } from '@/services/price-sheet/getPackageList'
import type { ComboPrice } from '@/services/price-sheet/getComboPriceList'
import { PermissionEnum } from '@/core/enums/auth'
import type { PriceSheet } from '@/core/interfaces/priceSheet'
import { type StatusEnum, ApproveStatusEnum } from '@/core/enums/status'
import { ProductEnum } from '@/core/enums/platform'
import type { CreativePictureEnum, VersionTypeEnum } from '@/core/enums/type'
import type { PriceKeyword } from '@/core/interfaces/keyword'
import type { VectorX } from '@/core/interfaces/priceTable'

interface PurchaseData {
  approveStatus: ApproveStatusEnum
  selectedData: PriceKeyword[]
  CibaoPriceData?: {
    comboName: PackageData['comboName']
    comboPriceName: ComboPrice['info']
  }
  HjbwPriceData?: {
    comboPriceName: ComboPrice['info']
  }
  Bw360PriceData?: {
    columnName: string
    comboPriceName: ComboPrice['info']
    quote: VectorX['quote']
  }
  BwPriceData?: {
    quote: VectorX['quote']
    comboPriceName: ComboPrice['info']
    columnName: string
    hasCreativePicture?: CreativePictureEnum
    versionType?: VersionTypeEnum
  }
  type: ProductEnum
}

export const usePriceSheetStore = defineStore('PriceSheet', () => {
  const currentPriceSheet = ref<Partial<PriceSheet>>({})
  const purchaseData = ref<PurchaseData>({
    selectedData: [],
    approveStatus: ApproveStatusEnum.PENDING,
    type: ProductEnum.BW
  })
  const detailPagePermission = ref<PermissionEnum>(PermissionEnum.DETAIL)

  function setCurrentPriceSheet(priceSheet: Partial<PriceSheet>) {
    currentPriceSheet.value = priceSheet
  }

  function setPurchaseData(payload: PurchaseData) {
    purchaseData.value = payload
  }

  function setHjbwPurchaseData(payload: PurchaseData) {
    purchaseData.value = payload
  }

  function setCurrentPriceSheetStatus(status: StatusEnum) {
    currentPriceSheet.value.status = status
  }

  function setDetailPagePermission(p: PermissionEnum) {
    detailPagePermission.value = p
  }

  return {
    currentPriceSheet,
    purchaseData,
    detailPagePermission,
    setCurrentPriceSheet,
    setPurchaseData,
    setCurrentPriceSheetStatus,
    setDetailPagePermission
  }
})
